
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.ArrayList,
                 com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User,
                 com.scalar.chiptrack.sales.CustomerPartNumber,
                 com.scalar.chiptrack.commons.Constants,
                 org.apache.struts.util.LabelValueBean"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/customerPartNumbers.do"/>

<html:html locale="true">

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</script>


<script language='javascript'>
var saved = false;
function save()
{
      //Added by Sarada on 10th Feb 2004
        var mfgPartNo = eval('document.customerPartNumbersForm.manufacturingPartNo');
        if (mfgPartNo.length ==  null )
        {
            mfgPartNo.disabled = false;
        }
        else
        {
          for (var k = 0; k < mfgPartNo.length; k++ )
            {
                mfgPartNo[k].disabled = false;
            }
         }

    if( saved == false )
    {
        saved = true;
        document.customerPartNumbersForm.submit();
    }
}
function submitPage( action )
{
    var errors = "";
    if ( action == 'SAVE')
    {
        manufacturingPartNo = document.customerPartNumbersForm["manufacturingPartNo"];
        odmId = document.customerPartNumbersForm["odmId"];
        productId = document.customerPartNumbersForm["productId"];
        customerPartNo = document.customerPartNumbersForm["customerPartNo"];
        labelNumber = document.customerPartNumbersForm["labelNumber"];
        /*for ( var i = 0 ; i < manufacturingPartNo.length - 1; i++ )
        {
            for ( var j = i+1 ; j < manufacturingPartNo.length; j++ )
            {
                if ( customerPartNo[i] != '' && customerPartNo[j] != '' && labelNumber[i] != '' && labelNumber[j] != '' && ( productId[i] == productId[j] ) && ( odmId[i] == odmId[j] ) );
                {
                    errors = "<br><li>Combination of Part Number and Odm should be unique";
                }
            }
        }
        for ( var i = 0 ; i < manufacturingPartNo.length ; i++ )
        {
            manufacturingPartNo[i].disabled = false;
        }*/
    }
    if ( errors == "" )
    {
        document.customerPartNumbersForm.action.value="SaveCustomerPartNumbers";
        document.customerPartNumbersForm.submit();
    }
    else
    {
        var pa = document.getElementById("errors1");
        pa.innerHTML = errors;
    }
}

function reset()
{
    document.customerPartNumbersForm.reset();
}
function closeWindow(form) {
	// window.opener.navigate(window.opener.document.location.href);

  //  form = window.opener.customerForm;
   // form.submit();
    window.close();
}
function addTextArea( rowId )
{
    var index = rowId.rowIndex + 1;
    var row = document.all.partNumbersTable.insertRow( index );
    var cell = row.insertCell(0);
    cell.style.textAlign="center";
    cell.style.backgroundColor="#FFFFEE";
    var htmltext = '<input type="text" name="manufacturingPartNo" value="'+rowId.all("manufacturingPartNo").value+'" disabled="disabled" size="23" class="txfield">';
    htmltext = htmltext + '<input type="hidden" name="hiddenMfgPartNo" value="'+rowId.all("manufacturingPartNo").value+'">'
    cell.innerHTML = htmltext;
    cell = row.insertCell(1);
    cell.style.backgroundColor="#FFFFEE";
    cell.style.textAlign="center";
    htmltext = '<input type="text" name="customerPartNo" maxlength="50" size="23" value="'+rowId.all("customerPartNo").value+'" class="txfield">';
    htmltext = htmltext + '<input type="hidden" name="productId" value="'+rowId.all("productId").value+'">';
    cell.innerHTML = htmltext;
    cell = row.insertCell(2);
    cell.style.backgroundColor="#FFFFEE";
    cell.style.textAlign="left";
    htmltext = '<select name="odmId" class="txfield" ><option value="-1" >----- Select -----</option>';
    <%
        ArrayList OdmList = ( ArrayList )session.getAttribute("odmNamesList");
        StringBuffer strbfr = new StringBuffer();
        try
        {
            if ( OdmList != null )
            {
                for (int i = 0; i < OdmList.size(); i++) {
                    LabelValueBean labelValueBean = (LabelValueBean) OdmList.get(i);
                    strbfr.append("htmltext = htmltext + '");
                    strbfr.append("<option value=\"").append(labelValueBean.getValue()).append("\">");
                    strbfr.append(labelValueBean.getLabel()).append("</option>';\n");
                }
            }
            out.println(strbfr);
        }
        catch( Exception e)
        {
            e.printStackTrace();
        }
    %>
    htmltext = htmltext + '</select>';
    cell.innerHTML = htmltext;
    <%if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() )){ %>
    cell = row.insertCell(3);
    cell.style.backgroundColor="#FFFFEE";
    htmltext = '<input type="text" name="labelNumber" maxlength="50" size="23" value="" class="txfield">';
    cell.innerHTML = htmltext;
    <%}else{%>
    cell = row.insertCell(3);
    cell.style.backgroundColor="#FFFFEE";
    htmltext = '<input type="hidden" name="labelNumber" maxlength="50" size="23" value="" class="txfield">';
    cell.innerHTML = htmltext;
    <%}%>
    row.all("odmId").focus();
}

//Added by Varma 10 Jan 2005
function showPrintView()
{
    var custId =  document.customerPartNumbersForm.customerId.value;
    newWindow = window.open ('<%=chipTracContext%>/customerPartNumbers.do?action=printView&customerId='+custId,'printView','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=600,height=600,left=100,top=50,resizable=yes');
    if(!newWindow.opener) {newWindow.opener = window}

}
function showErrorReportPage()
{
    newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
    newWindow.focus();
}

</script>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<!-- from here your body starts -->

<html:form name="customerPartNumbersForm" type="com.scalar.chiptrack.sales.forms.CustomerPartNumbersForm" action="/customerPartNumbers.do">


</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
<table border="0" width="90%" align=right>
 <tr><td>
<center><span class="NArialW">
<!-- Modified by veeru on (03/03/04)
Customer Part Numbers -->
<bean:message key="label.customerPartNumber"/>s

 <table border="0" width="100%" cellspacing='10' cellpadding='2' align='left'>
 <tr>
 <%if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() )){ %>
 <td colspan='4' align=left class="NArialL">Click here to <a href='javascript:showPrintView();'onmouseover="window.status='Click here to print/view';return true" onmouseout="window.status='';return true"> view/print </a><bean:message key="label.customerPartNumber"/>s Details</td>
 <%}%>
 <td  align=right><a href="javascript:closeWindow(document.customerPartNumbersForm);" onMouseOver="window.status='Click to close this window';return true" onmouseout="window.status='';return true"><font class='NArialL'>Close this window</font></a></td></tr>

 </table>
 </td></tr>
 <tr><td>
   <table border="0" width="70%" bordercolor="black" align="center" id="partNumbersTable">
   <!--tr><td colspan='5'></td></tr-->
   <!-----Don't Move any rows out side the table if so addrow will not work ------>
    <tr><td colspan='4'><chiptrack:errors styleClass='NArialL' /></td></tr>
    <tr><td colspan='4'><chiptrack:info styleClass='NArialL' /> </td></tr>
    <tr><td colspan="4" align="left" class='NArialL'><FONT id="errors1" styleClass="NArialL" color='FF0000'></FONT></TD></TR>
    <tr>
        <td colspan='1' align="center" bgcolor="#993333"><font class="NArialL">
			<!-- Modified by veeru on (03/05/04)
			<font color="#FFFFFF">Mfg Part Number</font> -->
			<font color="#FFFFFF"><bean:message key="label.mfgPartNumber" /></font>
			</font>
		</td>
        <td colspan='1' align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">
		<!-- Modified by veeru on (03/08/04)
		Customer Part Number -->
		<bean:message key="label.customerPartNumber"/>
		</font></font></td>


       <%-- <%if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() )){ %>--%>
        <td colspan='1' align="center" bgcolor="#993333"><font class="NArialL">
			<font color="#FFFFFF"><bean:message key="label.sales.endCustomer"/></font>
			</font>
		</td>
        <%if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() )){ %>
        <td colspan='1' align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">
        <bean:message key="label.labelNumber" />
		</font></font></td>
        <td>&nbsp;</td>
        <%}%>
    </tr>

    <% int bgcount = 0;%>
    <logic:iterate id="CustomerPartNumber" name="mfgPartsWithProductIds" type="com.scalar.chiptrack.sales.CustomerPartNumber">
    <% bgcount = bgcount + 1; %>


    <%  int lineitemid =CustomerPartNumber.getProductId();
    if(lineitemid == 0 ){
    int colSpan = 2;
    String align="center";
    //if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() )){
     colSpan = 3;
     align="left";
    //}
    %>
    <tr>
        <td bgcolor='#FFFFEE'><font class="NArialL">&nbsp;</font></td>
        <td align=<%=align%>  colspan=<%=colSpan%> bgcolor='#FFFFEE'><font class="NArialL">
        <html:text name="CustomerPartNumber" property="manufacturingPartNo" size="23" styleClass="txfield" disabled="true"/></font>
        <input type="hidden" name="hiddenMfgPartNo" value="<bean:write name="CustomerPartNumber" property="manufacturingPartNo"/>" ></td>
        <html:hidden name="CustomerPartNumber" property="customerPartNo" />
        <html:hidden name="CustomerPartNumber" property="labelNumber"/>
        <html:hidden name="CustomerPartNumber" property="odmId"/>
        <input type="hidden" name="productId" value="<%=CustomerPartNumber.getProductId()%>"/>
        </tr>
       <% } else{%>
    <tr id="rowId<%=bgcount%>">
    <td nowrap   colspan='1' align="center" bgcolor='#FFFFEE'><font class="NArialL">
    <!--input type="hidden" name="productId" value="<%= CustomerPartNumber.getProductId()%>"/-->
    <html:text name="CustomerPartNumber" property="manufacturingPartNo" size="23" styleClass="txfield" disabled="true"/></font>
    <input type="hidden" name="hiddenMfgPartNo" value="<bean:write name="CustomerPartNumber" property="manufacturingPartNo"/>" ></td>
    <td nowrap  colspan='1' align="center"  bgcolor='#FFFFEE'><font class="NArialL">
        <html:text name="CustomerPartNumber" property="customerPartNo" size="23" styleClass="txfield"  maxlength="50"/> </font>
        <input type="hidden" name="productId" value="<%=CustomerPartNumber.getProductId()%>"/>
    </td>

    <%--<%if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() )){%>--%>
    <td nowrap  colspan='1' align="center"  bgcolor='#FFFFEE'><font class="NArialL">
         <html:select name="CustomerPartNumber" property="odmId" styleClass="txfield" >
                <html:option value="-1" >----- Select -----</html:option>
                <html:options collection="odmNamesList" property="value" labelProperty="label"/>
         </html:select>
    </td>

    <bean:size id="listSize" name="odmNamesList" />

    <%if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() )){%>
    <td nowrap   colspan='1' align="center" bgcolor='#FFFFEE'><font class="NArialL">
    <html:text name="CustomerPartNumber" property="labelNumber" size="23" styleClass="txfield" maxlength="50"/></font>

    <%--<logic:greaterThan name="listSize" value="0">--%>
        <td>
        <a href="javascript:addTextArea(rowId<%=bgcount%>)" onMouseOver="window.status=''; return true " onMouseOut="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/add.jpg" height='15' width='20'></a>

        </td>
    <%--</logic:greaterThan>--%>
    </td>
    <%}else{%>
    <%--<html:hidden name="CustomerPartNumber" property="odmId"/>--%>
    <html:hidden name="CustomerPartNumber" property="labelNumber"/>

    <%--<logic:greaterThan name="listSize" value="0">--%>
        <td>
        <a href="javascript:addTextArea(rowId<%=bgcount%>)" onMouseOver="window.status=''; return true " onMouseOut="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/add.jpg" height='15' width='20'></a>
        </td>
    <%--</logic:greaterThan>--%>
    <%}%>
    <%} %>

    </tr>
    </logic:iterate>
    <tr>&nbsp;&nbsp;</tr>

    <!--tr><td class="NArialL" ><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=50></td></tr-->
    <!--tr>
        <td  nowrap align='center'>
		     <a href="javascript:save()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></a>
	    </td>
		<td  nowrap align='left'>
		     <a href="javascript:reset()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>
	    </td>
    </tr-->
    <!--tr><td  align=center><a href="javascript:closeWindow(document.customerPartNumbersForm);" onMouseOver="window.status='Click here to close this window';return true"><font class='NArialL'>Close this window</font></a></td></tr-->

    </table>



</td></tr>
  <tr>
        <td  nowrap colspan='1' align='center'>
             <%-- Commented by Krishna Prasad on 20 May 2004, due to improper submition of form --%>
		     <%--<a href="javascript:save()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></a>--%>
             <%-- Added by Krishna Prasad on 20 May 2004, due to above commented tag is not submiting the form properly--%>
             <%-- Modified by Veeru  on 29th Nov 2004--%>
             <%--<input type="image" onClick="javascript:save()" border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17" onMouseOver="window.status='Click to Add Customer Part Number';return true" onmouseout="window.status='';return true" title="Click here to Add Customer Part Number">--%>
             <chiptrack:restrictedLink functionality='<%=Functionality.CUSTOMER_DETAILS%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage('SAVE');" onmouseover="window.status='Click to Add Customer Part Number';return true" onmouseout="window.status='';return true">
             <img src="<%=chipTracContext%>/jsp/includes/images/save.gif" border='0' title="Click here to Add Customer Part Number"></chiptrack:restrictedLink>


	    <!--/td>
		<td  nowrap colspan='1' align='left'-->
		    &nbsp;&nbsp;&nbsp;&nbsp; <a href="javascript:reset()"onMouseOver="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>
	    </td>
    </tr>
<tr><td colspan='5' align=center><a href="javascript:closeWindow(document.customerPartNumbersForm);" onMouseOver="window.status='Click to close this window';return true" onmouseout="window.status='';return true"><font class='NArialL'>Close this window</font></a></td></tr>
</table>
<%String customerId =request.getParameter("customerId");
  //System.out.println("customerId  "+customerId);
%>
<input type="hidden" name="bgCount" value="<%=bgcount%>">
<input type="hidden" name="customerId" value="<%=customerId%>">
<input type="hidden" name="action">
</html:form>


</body>

</html:html>